package com.dy.查找.静态表查找.二分查找;

public class 二分查找 {
    static int binarySearch(int[] nums, int key) {
        int start = 0, end = nums.length - 1;
        while (start <= end) {
            int mid = start+(end-start)/2;
            if(nums[mid]==key) return mid;
            else if(nums[mid]>key){
                end=mid-1;
            }
            else start=mid+1;
        }
        return start;
    }
    public static void main(String[] args) {
        int a[]={1,2,3,4,5,6,9};
        System.out.println(binarySearch(a,1));
    }
}
